# -*- coding: utf-8 -*-
'''
Created on 12 mars 2011

@author: thierry
'''

from optparse import OptionParser
import logging

import core

LEVELS = {'debug': logging.DEBUG,
          'info': logging.INFO,
          'warning': logging.WARNING,
          'error': logging.ERROR,
          'critical': logging.CRITICAL}



def run():
    usage = "%prog -s <server> -u <user> -p <password> [-l <log level>]"
    str_version = "%prog 0.1"
    parser = OptionParser(usage=usage, version=str_version)
    parser.add_option("-s", "--server", action="store", type="string", dest="server", help="server url")
    parser.add_option("-u", "--user", action="store", type="string", dest="user", help="user login")    
    parser.add_option("-p", "--password", action="store", type="string", dest="password", help="user pasword")
    parser.add_option("-k", "--key", action="store", type="string", dest="key", help="api key")
    parser.add_option("--once", action="store_true", dest="once", help="update only on time then exit", default=False)
    parser.add_option("-l", "--log", action="store", type="string", dest="level_name", help="log level")
    options, args = parser.parse_args()

    level = LEVELS.get(options.level_name, logging.NOTSET)
    logging.basicConfig(level=level)
    
    logging.info("Web900 remote control")
    logging.info("=====================")
    logging.info("starting up deamon...")
    core.run(options.server, options.user, options.password, options.key, options.once)
    logging.info("running")


if __name__ == '__main__':
    run()

    
